home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / appsource.lha / APlusPlus / TESTPRGS / intuition / Constraints_test.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  5.5 KB  |  211 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:RCS/testprgs/intuition/Constraints_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *    $Revision: 1.6 $
  9.  *    $Date: 1994/07/23 19:15:19 $
  10.  *    $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14.  
  15. #include <APlusPlus/exec/SignalResponder.h>
  16. #include <APlusPlus/intuition/GWindow.h>
  17. #include <APlusPlus/intuition/IntuiMessageC.h>
  18. #include <APlusPlus/intuition/BoopsiGadget.h>
  19. #include <APlusPlus/intuition/StdGadget.h>
  20. #include <APlusPlus/graphics/GBorder.h>
  21.  
  22. extern "C" {
  23. #include <dos/dos.h>
  24. }
  25.  
  26. #include <iostream.h>
  27.  
  28.  
  29. static const char rcs_id[] = "$Id: Constraints_test.cxx,v 1.6 1994/07/23 19:15:19 Armin_Vogt Exp Armin_Vogt $";
  30.  
  31.  
  32. class MyBoopsi : public BoopsiGadget
  33. {
  34.    public:
  35.       MyBoopsi(GOB_OWNER,UBYTE *name,AttrList& attrs)
  36.       : BoopsiGadget(gob_owner,name,attrs) { }
  37.       ~MyBoopsi() {}
  38.  
  39.       // runtime type inquiry support
  40.       static const Intui_Type_info info_obj;
  41.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  42.          { return info_obj; }
  43.       static const Type_info& info()                // get the 'type_id' of a specific class
  44.          { return info_obj; }
  45.  
  46. };
  47.  
  48. intui_typeinfo(MyBoopsi, derived(from(BoopsiGadget)), rcs_id);
  49.  
  50.  
  51. BOOL running = TRUE;
  52. BOOL close2 = FALSE;
  53. GWindow *stop_window;
  54.  
  55.  
  56. class MySRSP : public SignalResponder
  57. {
  58.    public:
  59.       MySRSP(BYTE signal) : SignalResponder(signal,0) {}
  60.  
  61.       void actionCallback();
  62. };
  63.  
  64. // overload the virtual 'signal received' action callback method.
  65. void MySRSP::actionCallback()
  66. {
  67.    cout << "**Break\n";
  68.    running = FALSE;
  69. }
  70.  
  71. class MyWindow : public GWindow
  72. {
  73.    private:
  74.       void init();
  75.  
  76.    public:
  77.       MyWindow(OWNER,AttrList& attrs) : GWindow(owner,attrs) { init(); }
  78.       void On_CLOSEWINDOW(const IntuiMessageC *msg);
  79.       void On_ACTIVEWINDOW(const IntuiMessageC *msg);
  80.       void On_SIZEVERIFY(const IntuiMessageC *msg);
  81.       void handleIntuiMsg(const IntuiMessageC* imsg);
  82.  
  83.       // runtime type inquiry support
  84.       static const Intui_Type_info info_obj;
  85.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  86.          { return info_obj; }
  87.       static const Type_info& info()                // get the 'type_id' of a specific class
  88.          { return info_obj; }
  89.  
  90. };
  91.  
  92. intui_typeinfo(MyWindow, derived(from(GWindow)), rcs_id);
  93.  
  94.  
  95.  
  96.  
  97. void MyWindow::init()
  98. {
  99.    modifyIDCMP(CLASS_NEWSIZE|CLASS_CLOSEWINDOW|CLASS_ACTIVEWINDOW|CLASS_SIZEVERIFY);
  100. }
  101.  
  102. void MyWindow::On_CLOSEWINDOW(const IntuiMessageC *msg)
  103.       {
  104.          cout << "CLOSEWINDOW.\n";
  105.          if (this == stop_window) running = FALSE;
  106.          delete this;
  107.       }
  108. void MyWindow::On_ACTIVEWINDOW(const IntuiMessageC *msg)
  109.       {
  110.          cout << title() << " is ACTIVE.\n";
  111.       }
  112. void MyWindow::On_SIZEVERIFY(const IntuiMessageC *msg)
  113.       {
  114.          cout << "SIZEVERIFY. \n";
  115.       }
  116. void MyWindow::handleIntuiMsg(const IntuiMessageC* imsg)
  117.       {
  118.          switch (imsg->getClass())
  119.          {
  120.             case CLASS_CLOSEWINDOW :
  121.                On_CLOSEWINDOW(imsg); break;
  122.             case CLASS_ACTIVEWINDOW :
  123.                On_ACTIVEWINDOW(imsg); break;
  124.             case CLASS_SIZEVERIFY :
  125.                On_SIZEVERIFY(imsg); break;
  126.          }
  127.          GWindow::handleIntuiMsg(imsg);
  128. }
  129.  
  130.  
  131. void APPmain(int argc,char* argv[])
  132. {
  133.    MySRSP sr(SIGBREAKB_CTRL_C);
  134.  
  135.    LineBorder LBorder;
  136.  
  137.    MyWindow *little = new MyWindow(OWNER_NULL,
  138.       AttrList( WA_Title,(ULONG)"Window - close this to stop.",
  139.       WA_Left,200,
  140.       WA_Top,200,
  141.       WA_Width,300,
  142.       WA_Height,150,
  143.       WA_MinHeight,40,
  144.       WA_MaxHeight,1600,
  145.       WA_MaxWidth,1600,
  146.       WA_DragBar,TRUE,
  147.       WA_SizeGadget,TRUE,
  148.       WA_DepthGadget,TRUE,
  149.       WA_CloseGadget,TRUE,
  150. //    GOB_BorderObj(&border),
  151.       TAG_END) );
  152.  
  153.    cout<<"TEST: little window created.\n";
  154.  
  155.    MyBoopsi *prop1 = new MyBoopsi(little,
  156.       (UBYTE*)"propgclass",
  157.       AttrList( GOB_LeftFromRightOfParent,-10,
  158.       GOB_TopFromTopOfParent,0,
  159.       GOB_RightFromRightOfParent,-1,
  160.       GOB_BottomFromBottomOfParent,0,
  161.       GA_Immediate,TRUE,
  162.       GA_RelVerify,TRUE,
  163.       PGA_Freedom,FREEVERT,
  164.       PGA_Top,200,
  165.       PGA_Total,2000,
  166.       PGA_Visible,300,
  167.       ICA_TARGET,ICTARGET_IDCMP,
  168.       PGA_NewLook,TRUE,
  169.       GOB_BorderObj(&LBorder),
  170.       TAG_END) );
  171.  
  172.    BevelBox BBorder;
  173.  
  174.    MyBoopsi *prop2 = new MyBoopsi(little,
  175.       (UBYTE*)"propgclass",
  176.       AttrList(
  177.       GOB_LeftFromLeftOfParent,2,
  178.       GOB_TopFromTopOfParent,2,
  179.       GOB_RightFromLeftOfParent,15,
  180.       GOB_BottomFromBottomOfParent,-10,
  181.       GA_Immediate,TRUE,
  182.       GA_RelVerify,TRUE,
  183.       PGA_Freedom,FREEVERT,
  184.       CONSTRAINT( PGA_Top,prop1,PGA_Top ),
  185.       PGA_Total,2000,
  186.       PGA_Visible,1000,
  187.       ICA_TARGET,ICTARGET_IDCMP,
  188.       PGA_NewLook,TRUE,
  189.       GOB_BorderObj(&BBorder),
  190.       TAG_END) );
  191.  
  192.    prop1->setAttributes( AttrList( CONSTRAINT( PGA_Top,prop2,PGA_Top ), TAG_END) );
  193.  
  194.    if (! APPOK(prop2) )
  195.       cerr << " APPOK() on "<<(APTR)prop2<<" failed, status "<<(LONG)prop2->status()<<"\n";
  196.    if (! APPOK(prop1) )
  197.       cerr << "prop1 invalid\n";
  198.  
  199.    stop_window = little;
  200.    cout << little <<endl;
  201.    cout << "sizeof( )"<<"\nBoopsigadget\t"<<sizeof(MyBoopsi)<<endl<<"\nGWindow\t"<<sizeof(GWindow)<<endl;
  202.    little->refreshGList();
  203.  
  204.    while (running)
  205.    {
  206.       SignalResponder::WaitSignal();
  207.    }
  208.  
  209.    cout << "cleaned up. goodbye.\n";
  210. }
  211.